<html lang="zh-CN"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="format-detection" content="telephone=no">
<title>我的商品</title>
<link rel="stylesheet" type="text/css" href="../addons/weisrc_dish/template/css/1/wei_canyin_v1.8.4.css?v=1.1.2" media="all">
<link rel="stylesheet" type="text/css" href="../addons/weisrc_dish/template/css/1/wei_dialog_v1.2.1.css?v=1.0" media="all">
<script type="text/javascript" src="../addons/weisrc_dish/template/js/1/wei_webapp_v2_common_v1.9.4.js"></script>
<script type="text/javascript" src="../addons/weisrc_dish/template/js/1/wei_dialog_v1.9.9.js?v=1"></script>
<script type="text/javascript" src="../addons/weisrc_dish/template/js/2/jQuery.js"></script>
<link rel="stylesheet" type="text/css" href="../addons/weisrc_dish/template/css/2/mobiscroll.custom-2.6.2.min.css" media="all">
<link data-turbolinks-track="true" href="{RES}/mobile/{php echo $this->cur_tpl}/assets/diandanbao/font.css?v=1" media="all" rel="stylesheet">
<script type="text/javascript" src="../addons/weisrc_dish/template/js/2/mobiscroll.custom-2.6.2.min.js"></script>
<link data-turbolinks-track="true" href="{RES}/mobile/{php echo $this->cur_tpl}/assets/diandanbao/menu.css?v=1" media="all" rel="stylesheet">
    <script type="text/javascript">
        $(function () {
            var dat = new Date();
            var curr = dat.getFullYear();
            var currM = dat.getMonth();
            var currD = dat.getDate();
            var opt = {}
            opt.date = { preset: 'date', minDate: new Date(curr, currM, currD, 9, 22), maxDate: new Date(curr, currM + 1, currD, 15, 44), stepMinute: 5 };
            opt.datetime = { preset: 'datetime', minDate: new Date(2012, 3, 10, 9, 22), maxDate: new Date(2014, 7, 30, 15, 44), stepMinute: 5 };
            opt.time = { preset: 'time' };
            $('#sdate').scroller('destroy').scroller($.extend(opt['date'], { theme: 'ios', mode: 'scroller', display: 'bottom', lang: 'zh', dateOrder: 'yymmdd', dateFormat:           'yy-mm-dd' }));
        });
    </script>
</head>
<body id="page_intelOrder" class="myOrderCon">
<div class="ddb-nav-header ng-scope">
    <a class="nav-left-item" href="javascript:void(0)" onclick="history.go(-1)"><i class="fa fa-angle-left"></i></a>
    <div class="header-title ng-binding">购物车</div>
    <a class="nav-right-item" href="#"></a>
</div>
<div class="center">
    <section style="margin-bottom: 10px;margin-top: 40px;display: none;">
        <article style="overflow: hidden;">
            <a href="{php echo $this->createMobileurl('order', array(), true)}" class="btn_add btn_myorder" style="color:#fff;">我的订单</a>
            <span style="float: right;">{$my_order_total}</span>
        </article>
    </section>
    {if $flag == true}
    <section style="margin-bottom: 20px;margin-top: 40px;">
        <article>
            <form id="form2" target="hide">
                <input type="hidden" name="id" value="">
                <table class="table_book">
                    <tbody>
                    <tr>
                        <td width="80px" style="width: 80px;">手机号码：</td>
                        <td colspan="2">
                            <input type="tel" name="entry_mobile" id="entry_mobile" placeholder="请输入手机号码" maxlength="15" class="input" style="width: 200px;"/>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 80px;">验证码：</td>
                        <td colspan="2">
                            <input type="number" placeholder="验证码：" name="entry_checkcode" id="entry_checkcode" maxlength="10" class="input" style="width: 100px;"/>
                            <input type="button" onclick="getReceiveMemberCardVCode(this, event,'form2', 'entry_mobile',2);" class="button vcode" value="获取验证码" style="width: 100px;height: 40px"/>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <footer>
                    <input type="button" value="提交" class="btn_2" id="submit_form2">
                </footer>
            </form>
        </article>
    </section>
    <style>
        .input{
            display: inline-block;
            padding:11px 5px;
            border:1px solid #dddddd;
            border-radius:3px;
            width:100%;
            background:#f3f3f3;
            -webkit-box-sizing:border-box;
            color:#606366;
        }
        .button{
            display: inline-block;
            line-height: 40px;
            font-size:12px;
            text-align: center;
            color:#ffffff;
            border:1px solid #c3cfd0;
            border-radius: 1px;
            background:#56c6d6;
            border: 0;
        }
        .button.vcode{
            width:80px;
        }
        .button.vcode[disabled]{
            background:#cccccc;
            font-size: 12px;
        }
    </style>
    {else}
    <input type="hidden" id="mode" value="{$mode}" name="mode">
    <input type="hidden" id="tables" value="{$tablesid}" name="tables">
    <section style="margin-bottom: 10px;margin-top: 40px;">
        <article style="overflow: hidden;">
            {if $mode == 1}
            <h2 style="color:#f00;">{$table_title}</h2>
            {/if}
            <div id="form_dish" target="hide" {if $mode == 1}style="border-top: 1px #e7eaeb solid;margin-top: 10px;"{/if}>
                <table class="table_book">
                    <tbody>
                    <tr>
                        <td style="width: 80px;">优惠券：</td>
                        <td colspan="2">
                            <select name="coupon" id="coupon" onchange="select_coupon(this)">
                                {if empty($couponlist)}
                                <option value="0">无可用优惠券</option>
                                {else}
                                <option value="0">未选择优惠</option>
                                {loop $couponlist $item}
                                <option value="{$item['couponid']}">{$item['title']}</option>
                                {/loop}
                                {/if}
                            </select>
                        </td>
                    </tr>
                    {if $mode == 2}
                    {if $store['delivery_within_days'] != 0}
                    <tr>
                        <td style="width: 80px;">配送日期：</td>
                        <td colspan="2">
                            <select name="meal_date" id="meal_date" onchange="changeMealDate(this)">
                                {$select_mealdate}
                            </select>
                        </td>
                    </tr>
                    {else}
                    <input type="hidden" id="meal_date" value="" name="meal_date">
                    {/if}
                    <tr>
                        <td style="width: 80px;">配送时间：</td>
                        <td colspan="2">
                            <select name="meal_time" id="meal_time">
                                {$select_mealtime}
                            </select>
                        </td>
                    </tr>
                    {if $store['dispatchprice']>0}
                    <tr>
                        <td style="width: 80px;">配送费用：</td>
                        <td colspan="2">
                            {$store['dispatchprice']} {if $store['freeprice']!=0.00}(<font color="#f00">消费满{$store['freeprice']}免配送费用</font>){/if}
                        </td>
                    </tr>
                    {/if}
                    {if $delivery_radius>0}
                    <tr>
                        <td style="width: 80px;">配送范围：</td>
                        <td colspan="2">
                            {if $delivery_radius>0}{$delivery_radius}公里{/if}
                        </td>
                    </tr>
                    {/if}
                    {/if}
                    {if $mode != 1}
                    <tr>
                        <td width="80px" style="width: 80px;">手机号码：</td>
                        <td colspan="2">
                            <input type="tel" id="tel" name="tel" value="{if !empty($user['mobile'])}{$user['mobile']}{/if}" maxlength="13" placeholder="请输入手机号码"></td>
                    </tr>
                    <tr>
                        <td style="width: 80px;">用户姓名：</td>
                        <td colspan="2">
                            <input type="text" name="guest_name" id="name" value="{if !empty($user['username'])}{$user['username']}{/if}" maxlength="10" placeholder="请输入您的姓名">
                        </td>
                    </tr>
                    {/if}
                    {if $mode == 2}
                    <tr>
                        <td width="80px" style="width: 80px;">地址：</td>
                        <td colspan="2">
                            <input type="text" id="address" name="address" value="{if !empty($order['address'])}{$order['address']}{/if}" placeholder="请输入您的联系地址！">
                        </td>
                    </tr>
                    {/if}
                    {if $mode == 1}
                    <tr>
                        <td style="width: 80px;">用餐人数：</td>
                        <td colspan="2">
                            <input type="tel" id="counts" name="counts" value="" maxlength="3" placeholder="请填写用餐人数">
                        </td>
                    </tr>
                    {/if}
                    <tr>
                        <td style="width: 80px; vertical-align: top; line-height: 25px;">备注说明：</td>
                        <td colspan="2">
                            <textarea name="remark" id="remark" style="height: 60px;" maxlength="100" placeholder="请输入备注(可不填)"></textarea>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </article>
    </section>
    <div class="header">
        <input type="hidden" id="packvalue" value="{$packvalue}" name="packvalue">
        <input type="hidden" id="totalprice" value="{$totalprice}" name="totalprice">
        <input type="hidden" id="totalcount" value="{$totalcount}" name="totalcount">
        <input type="hidden" id="limitprice" value="{$limitprice}" name="limitprice">
        <input type="hidden" id="dprice" value="" name="dprice">
        <input type="hidden" id="dispatchprice" value="{$store['dispatchprice']}" name="dispatchprice">
        <input type="hidden" id="limitdispatchprice" value="{$store['freeprice']}" name="limitdispatchprice">
        <input type="hidden" id="over_radius" value="{$over_radius}" name="over_radius">
        <input type="hidden" id="btnstatus" value="0" name="btnstatus">
        <div class="left" style="padding-left: 15px;">还需支付￥<span id="totalpriceshow">{$totalprice}</span></span></div>
        <div class="right"><a id="btnselect" class="xhlbtn disable" href="javascript:void(0)">确认下单</a></div>
    </div>
    {/if}
{if $flag != true}
<section style="margin-bottom: 10px;margin-top: 10px;">
    <article>
        <h2>商品清单
            <button class="btn_add emptyIt" id="clearBtn">清空</button>
            <button class="btn_add" onclick="location.href='{php echo $this->createMobileUrl('waplist', array('storeid' => $storeid, 'mode' => $mode, 'tablesid' => $tablesid), true)}'">+继续选购</button>
        </h2>
        <ul class="myorder" id="myorder">
            {loop $cart $item}
            <li>
                <span class="dishName">{$item['title']}</span>
                <i>{$item['marketprice']}元/{$item['unitname']}<span class="yuanjia">{$item['productprice']}元/{$item['unitname']}</span></i>
                <section class="bbox" dishid="{$item['id']}" dishname="{$item['title']}">
                    <!--<input class="btn-reduce" type="button" value="-">-->
                    <input class="numBox" name="numBox" type="text" value="{$item['total']}" price="{$item['marketprice']}" disabled="disabled">{$item['unitname']}
                    <!--<input type="button" class="btn-plus" value="+">-->
                </section>
            </li>
            {/loop}
            <li style="{if $mode==2}height: 85px;{else}height: 65px;{/if}">
                <span class="dishName">商品价格:￥{$totalprice}</span>
                {if $mode==2 && $packvalue>0}
                <span class="dishName">打包费用:￥{$packvalue}</span>
                {/if}
                <span class="dishName" id="youhui">优惠抵扣:￥0</span>
                {if $store['dispatchprice']>0 && $mode==2}
                {if $totalprice<=$store['freeprice'] && $store['freeprice']>0}
                <span class="dishName">配送费用:￥{$store['dispatchprice']}</span>
                {/if}
                {/if}
            </li>
        </ul>
    </article>
</section>
{/if}
<div style="padding-top: 20px;"></div>
</div>
{if $flag != true}
<script>
    function changeMealDate(obj) {
        var time1 = '{$select_mealtime}';
        var time2 = '{$select_mealtime2}';
        var curdate = "{$cur_date}";
        if (obj.value == curdate) {
            $("#meal_time").html(time1);
        } else {
            $("#meal_time").html(time2);
        }
    }

    function changeBtnSelect() {
        var limitprice = parseFloat(_q("#limitprice").value);
        var totalprice = parseFloat(_q("#totalprice").value);
        if (limitprice > 0) {
            if (totalprice >= limitprice) {
                _removeClass(_q("#btnselect"),'disable');
                _q("#btnstatus").value = '1';
            } else {
                _addClass(_q("#btnselect"),'disable');
                _q("#btnstatus").value = '0';
            }
        } else {
            if (totalprice > 0) {
                _q("#btnstatus").value = '1';
                _removeClass(_q("#btnselect"),'disable');
            } else {
                _q("#btnstatus").value = '0';
                _addClass(_q("#btnselect"),'disable');
            }
        }
    }
</script>
{/if}
<script>var pageName = 'menuFilled';</script>
<script type="text/javascript">
var reduce = _qAll('.btn-reduce');
var plus = _qAll('.btn-plus');
var share = _qAll('.shareBtn');
//金额累加操作
"{if $flag != true}"
function tototal(){
    var total = 0;
    var nums = _qAll('.numBox');
    for( var j = 0; j < nums.length; j++){
        total = total + nums[j].value * nums[j].getAttribute('price');
    }
    goodstotal = parseFloat(total).toFixed(2) * 100/100;

    var limitdispatchprice = parseFloat(_q("#limitdispatchprice").value);
    var dispatchprice = parseFloat(_q("#dispatchprice").value);
    var packvalue = parseFloat(_q("#packvalue").value);
    var dprice = _q("#dprice").value;

    mode = $("#mode").val();
    var pricedetail = '';
    if (mode == 2) { // 外卖
        if (limitdispatchprice > 0) { //满多少免配送费
            if (goodstotal >= limitdispatchprice) { //免配送费
                endTotal = goodstotal;
            } else {
                endTotal = goodstotal + dispatchprice;
            }
        } else {
            endTotal = goodstotal + dispatchprice;
        }
        endTotal = endTotal + packvalue;

        _q('#totalprice').value = endTotal;
    } else {
        endTotal = goodstotal;
        _q('#totalprice').value = endTotal;
    }
    if (dprice != '') {
        dprice = parseFloat(dprice);
        pricedetail = pricedetail + '-' + dprice;
        endTotal = endTotal - dprice;
        _q('#totalprice').value = endTotal;

    }

    if (pricedetail == '') {
        _q("#totalpriceshow").innerHTML = endTotal;
    } else {
        _q("#totalpriceshow").innerHTML = endTotal;
        _q("#youhui").innerHTML = '优惠抵扣:￥' + pricedetail;
    }
    changeBtnSelect();
    return endTotal;
}
tototal();//初始化金额

function doSelectBtn(){
    var btn = _qAll("article ul li .bbox");
        var btnIndex = 0,btnLength = btn.length;
    for(btnIndex;btnIndex<btnLength;btnIndex++){
        var countNumText=parseInt(btn[btnIndex].children[1].value),
            btnAdd=btn[btnIndex].children[2],
            btnMin=btn[btnIndex].children[0];
        var iTimeout,iInterval,originalNum,
            beforeRemoveDish = false;
        btnAdd.addEventListener(_movestartEvt,function(){
            var _self = this;
            originalNum = parseInt(_self.parentNode.children[1].value, 10);
            countNumText =  originalNum +1;
            _self.parentNode.children[1].value = countNumText;
            iTimeout = setTimeout(function(){
                iInterval = setInterval(function(){
                    countNumText++;
                    _self.parentNode.children[1].value = countNumText;
                },100)
            },1000)
        })
        btnAdd.addEventListener(_moveendEvt,function(){
            //alert(countNumText)
            //_doAjax()...
            clearTimeout(iTimeout);
            clearInterval(iInterval);
            tototal();
            var _self = this;
            var countNumText =  parseInt(_self.parentNode.children[1].value, 10);
            var dishid = _self.parentNode.getAttribute('dishid');
            ajaxDishReset(dishid, countNumText, function(){}, function() {
                _self.parentNode.children[1].value = originalNum;
                tototal();
            });
            // countNumText = 0;
        })

        btnMin.addEventListener(_movestartEvt,function(){
            var _self = this;
            originalNum = parseInt(_self.parentNode.children[1].value, 10);
            countNumText =  originalNum -1;
            if(countNumText <= 0){
                beforeRemoveDish = true;
            }else{
                _self.parentNode.children[1].value = countNumText;
                iTimeout = setTimeout(function(){
                    iInterval = setInterval(function(){
                        if(countNumText<=0){
                            beforeRemoveDish = true;
                            _self.parentNode.children[1].value = originalNum;
                            clearInterval(iInterval);
                            return;
                        }
                        countNumText--;
                        _self.parentNode.children[1].value = countNumText;
                    },100)
                },1000)
            }
        })

        btnMin.addEventListener(_moveendEvt,function(){
            clearTimeout(iTimeout);
            clearInterval(iInterval);
            _self = this;

            var dishid = _self.parentNode.getAttribute('dishid');
            var dishName = _self.parentNode.getAttribute('dishName');
            var countNumText =  parseInt(_self.parentNode.children[1].value, 10);

            if(beforeRemoveDish){
                setTimeout(function(){
                    MDialog.confirm(
                        '', '是否删除' + dishName +'？', null,
                        '确定', function(){
                            ajaxDishRemove(dishid, function(){
                                var li = _self.parentNode.parentNode;
                                li.parentNode.removeChild(li);
                                var total = tototal();
                                // 没有数据后刷新页面
                                if (total == 0) {
                                    location.reload();
                                }
                            }, function() {
                                _self.parentNode.children[1].value = originalNum;
                                tototal();
                            });
                        }, null,
                        '取消', null, null,null, true, true
                    );
                },500)
                beforeRemoveDish = false;
            } else {
                tototal();
                ajaxDishReset(dishid, countNumText, function(){}, function() {
                     _self.parentNode.children[1].value = originalNum;
                    tototal();
                });
            }
        })
    } // for

    //更新分类菜品数量
    function ajaxDishReset(dishid, o2uNum, successCallback, errorCallback) {
        var params = {
            'dishid' : dishid,
            'o2uNum' : o2uNum
        };
        var url = "{php echo $this->createMobileUrl('UpdateDishNumOfCategory', array('storeid' => $storeid, 'from_user' => $from_user), true)}";
        _doAjax(url, 'POST', params, function(ret) {
            if (ret['message']['code'] != 0) {
                errorCallback();
                alert(ret['message']['msg']);
                return;
            } else {
                successCallback();
            }
            successCallback();
        });
    } // ajaxDishReset

    function ajaxDishRemove(dishid, successCallback, errorCallback) {
        var params = {
            'dishid' : dishid,
            'action' : 'remove'
        };

        var url = "{php echo $this->createMobileUrl('RemoveDishNumOfCategory', array('storeid' => $storeid, 'from_user' => $from_user), true)}";

        _doAjax(url, 'POST', params, function(ret) {
            if (ret['message']['code']!= 0) {
                errorCallback();
                alert(ret['message']['msg']);
                return;
            } else {
                successCallback();
            }
        });
    } // ajaxDishRemove
} // doSelectBtn
"{/if}"
_onPageLoaded(function(){
    var reduce = _qAll('.btn-reduce');
    var plus = _qAll('.btn-plus');
    "{if $flag != true}"
    tototal();//初始化金额
//    doSelectBtn();
    "{/if}"

    var url =
            "{php echo $this->createMobileUrl('clearmenu', array('storeid' => $storeid, 'from_user' => $from_user, 'mode' => $mode), true)}";
    "{if $flag != true}"
    _q('#clearBtn').onclick = function() {
        MDialog.confirm(
            '', '是否清空菜单？', null,
            '确定', function(){
                window.location.href = url;
            }, null,
            '取消', null, null,
            null, true, true
        );
    };
    "{/if}"

    $("#btnselect").click(function () {
        var bool = checkItem();
        if (bool) {
            MDialog.confirm(
                '', '确认提交吗？', null,
                '确定', function(){
                    postmain();
                }, null, '取消', null, null,null, true, true
            );
        }
    });

    $("#submit_form2").click(function () {
        var mobile = $("#entry_mobile").val();
        var checkcode = $("#entry_checkcode").val();
        if (mobile == "") {
            alert('请输入手机号码!');
            return false;
        }
        if (checkcode == "") {
            alert('请输入验证码!');
            return false;
        }
        MDialog.confirm(
            '', '确认提交吗？', null,
            '确定', function(){
                postmain2();
            }, null, '取消', null, null,null, true, true
        );
    });
});

function checkItem() {
    var ordertype = $("#mode").val();
    var meal_time = $("#meal_time").val();
    if (ordertype != 1) {
        if (!checkMobile($("#tel").val())) {
            return false;
        }
        if ($("#name").val() == "" || $("#name").val() == "(必填*)请输入您的真实姓名") { alert("请输入您的真实姓名！"); return false; }
    }
    totalprice = parseFloat(_q("#totalprice").value);

    if (totalprice <= 0) { alert("金额为0，请选择菜品！"); return false; }

    if (ordertype == 1) { //店内
        if ($("#counts").val() == "") { alert("请输入用餐人数！"); return false; }
        if (!new RegExp("^[0-9]*$").test($("#counts").val())) { alert("用餐人数只能为数字！"); return false; }
        if ($("#tables").val() == "") { alert("请输入桌号！"); return false; }
    } else if (ordertype == 2){//外卖
        if ($("#address").val() == "" || $("#address").val() == "(必填*)请输入您的联系地址！") { alert("请输入您的联系地址！"); return false; }
        if (meal_time == '休息中') {
            alert('未在配送时间！');
            return false;
        }
        var over_radius = $("#over_radius").val();
        if (over_radius == 1) {
            alert('超出配送范围，不允许下单！');
            return false;
        }
    } else if (ordertype == 4){//快餐

    }
    return true;
}

function postmain() {
    var status = _q("#btnstatus").value;
    var ordertype = $("#mode").val();
    var mealtime = $("#meal_date").val() + ' ' + $("#meal_time").val();
    if ($("#meal_date").val() == undefined) {
        if ($("#meal_time").val() == undefined) {
            mealtime = '';
        } else {
            mealtime = $("#meal_time").val();
        }
    }

    if (status == 0) {
        return false;
    }

    $("#btnselect").hide();
    if (true) {
        var data = "[";
        var myfoodlist = $("#myorder li");
        if (myfoodlist.length == 0) { return; }
        for (var i = 0; i < myfoodlist.length; i++) {
            data += "{"; data += "\"sid\":\"" + myfoodlist.eq(i).attr("name") + "\",";
            data += "\"counts\":\"" + myfoodlist.eq(i).find(".numBox").val() + "\""; data += "},";
        }
        data = data.substring(0, data.length - 1); data += "]";
        var url = "{php echo $this->createMobileUrl('addtoorder', array('storeid' => $storeid, 'from_user' => $from_user), true)}";

        var address = $("#address").val();
        var totalprice = parseFloat(_q("#totalprice").value);
        var couponid = $("#coupon").val();

        $.ajax({
            url: url, type: "post", dataType: "json", timeout: "10000",
            data: {
                "type": "add", "total": totalprice, "ordertype":ordertype,"tables": $("#tables").val(),
                "guest_name": $("#name").val(), "tel": $("#tel").val(), "sex": 1,
                "couponid" : couponid,
                "meal_time": mealtime,
                "counts": $("#counts").val(),
                "seat_type": $("input:radio[name='seat_type']:checked").val(), "remark": $("#remark").val(), "data": data, "carports": $("#carports").val(), "address":address
            },
            success: function (data) {
                if (data.message['code'] != 0) {
                    var url = "{php echo $this->createMobileUrl('pay', array(), true)}"+"&orderid="+data.message['orderid'];
                    location.href = url;
                } else {
                    alert(data.message['msg']);
                    //'网络不稳定，请重新尝试!'
                }
                $("#btnselect").show();
            },error: function () {
                alert("订单提交失败！");
            }
        });
    } else {
        $("#btnselect").show();
    }
}

function postmain2() {
    $("#submit_form2").hide();
    if (true) {
        var url = "{php echo $this->createMobileUrl('validatecheckcode', array('from_user' => $from_user), true)}";

        var mobile = $("#entry_mobile").val();
        var checkcode = $("#entry_checkcode").val();
        if (!checkMobile(mobile)) {
            return false;
        }

        if (checkcode == "") {
            alert('请输入验证码!');
            return false;
        }

        $.ajax({
            url: url, type: "post", dataType: "json", timeout: "10000",
            data: {
                "mobile": mobile,
                "checkcode": checkcode
            },
            success: function (data) {
                if (data.status == 1) {
                    window.location.reload();
                } else {
                    alert(data.msg);
                }
                $("#submit_form2").show();
            },error: function () {
                alert("网络不稳定，请重新尝试!");
            }
        });
    } else {
        $("#submit_form2").show();
    }
}

function select_coupon(obj) {
    couponid = obj.value;
    if (couponid == 0) {
        _q('#dprice').value = '';
        tototal();
        return false;
    }

    if (true) {
        var url = "{php echo $this->createMobileUrl('selectcoupon', array(), true)}";
        $.ajax({
            url: url, type: "post", dataType: "json", timeout: "10000",
            data: {
                "couponid": couponid
            },
            success: function (data) {
                if (data.status == 1) {
                    _q('#dprice').value = data.dprice;
                } else {
                    _q('#dprice').value = '';
                }
                tototal();
            },error: function () {

            }
        });
    }
}
</script>
<script type="text/javascript">
    var intervalId,buttonObj;
    //发送下一条短信需要间隔的秒数
    var seconds = 60;
    function getReceiveMemberCardVCode(clickObj, evt, formId, teleName, ch_type){
        var form = document.getElementById(formId);
        var url = "{php echo $this->createMobileurl('GetCheckCode', array('from_user' => $from_user), true);}";
        var storeid = "{$storeid}";
        var mobile = $.trim(form[teleName].value);
        var req = {
            mobile: mobile,
            storeid: storeid
        }
        if (!checkMobile(mobile)) {
            return false;
        }
        clickObj.setAttribute("disabled", "disabled");
        clickObj.value = "正在发送，请稍候...";

        $.ajax({
            url: url,
            type:"post",
            data:req,
            dataType:"JSON",
            success: function(data) {
                if (data.status == 1) {
                    clickObj.value = '发送成功';
                    buttonObj = clickObj;
                    intervalId = setInterval("ticker()",1000);
                } else {
                    clickObj.value = '发送失败';
                    buttonObj = clickObj;
                    intervalId = setInterval("ticker()",1000);
                    alert('调试:' + data.msg);
                    return false;
                }
            },
            error: function(data){
                alert('网络异常哦!');
                return false;
            }
        });
    }

    function ticker(){
        seconds --;
        if(seconds > 55){
            //提示消息显示5秒钟
        }else if(seconds>0){
            buttonObj.value = seconds+"秒后可重新获取";
        }else{
            clearInterval(intervalId);
            buttonObj.removeAttribute("disabled");
            buttonObj.value = "获取验证码";
            seconds = 60;
            buttonObj = null;
        }
    }

    function checkMobile($mobileVal) {
        if (checkEmpty($mobileVal) == false) {
            alert("请输入手机号码");
            return false;
        } else {
            if ($mobileVal.length != 11) {
                alert('手机号码长度不正确');
                return false;
            }
            else if (/^(((13[0-9]{1})|15[0-9]{1}|17[0-9]{1}|18[0-9]{1}|14[0-9]{1})+\d{8})$/.test($mobileVal) == false) {
                alert('手机号码格式不正确');
                return false;
            }
            else {
                return true;
            }
        }
    }

    //非空校验
    function checkEmpty(param) {
        if (param == "" || param == null || param == undefined) {
            return false;
        } else {
            return true;
        }
    }
</script>
</body>
</html>